/**
 * Map Diagram Service
 * 描绘柱状图、折线图、饼图等功能，目前以echarts为主
 */

angular.module('NxtMap')
  .service('MapDiagram', MapDiagram);

function MapDiagram() {

  //描绘echarts柱状图
  this.drawBar = function (e, dataMap){
    var myChart = echarts.init(document.getElementById(e));
    var option = {
      color: ['#418CFF'],
      tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
          type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
      },
      textStyle: {
        // color: '#333333',
        fontFamily: 'Microsoft YaHei',
        // fontWeight: 'lighter'
      },
      grid: {
        top: '5%',
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      yAxis : [
        {
          type : 'category',
          data : dataMap.legend,
          axisLabel: {
            rotate: 30,
            formatter: function (p) {
              return p.substring(0, 2);
            }
          },
          axisTick: {
            alignWithLabel: true
          }
        }
      ],
      xAxis : [
        {
          type : 'value',
          position: 'top',
          axisTick:{
            show: false
          },
          axisLine: {
            show: false
          }
        }
      ],
      series : [{
        name: '警情数',
        type:'bar',
        // itemStyle: {
        //   normal: {
        //     label : {
        //       show: true, position: 'top'
        //     }
        //   }
        // },
        data: dataMap.value
      }]
    };
    myChart.setOption(option);
  }

  //描绘echarts折线图
  this.drawLine = function (e, dataMap){
    var myChart = echarts.init(document.getElementById(e));
    var option = {
      color: ['#418CFF'],
      tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
          type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
      },
      textStyle: {
        // color: '#333333',
        fontFamily: 'Microsoft YaHei',
        // fontWeight: 'lighter'
      },
      grid: {
        top: '5%',
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis : [
        {
          type : 'category',
          data : dataMap.legendTime,
          // axisLabel: {
          //   rotate: 90,
          //   formatter: function (p) {
          //     return p.substring(0, 2);
          //   }
          // },
          splitLine: {
            show: true
          },
          axisTick:{
            show: false
          },
          axisLine: {
            show: false
          }
        }
      ],
      yAxis : [
        {
          type : 'value',
          splitLine: {
            show: true
          },
          axisTick:{
            show: false
          },
          axisLine: {
            show: false
          }
        }
      ],
      series : [{
        name: '警情数',
        type:'line',
        // itemStyle: {
        //   normal: {
        //     label : {
        //       show: true, position: 'top'
        //     }
        //   }
        // },
        data: dataMap.valueTime
      }]
    };
    myChart.setOption(option);
  }

 //折线图
  this.drawMultipleLine= function(e,dataMap){
    var myChart = echarts.init(document.getElementById(e));
    var option = {
      tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
          type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
      },
      textStyle: {
        // color: '#333333',
        fontFamily: 'Microsoft YaHei',
        // fontWeight: 'lighter'
      },
      grid: {
        top: '5%',
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      yAxis : [
        {
          type : 'value',
          splitLine: {
            show: true
          },
          axisTick:{
            show: false
          },
          axisLine: {
            show: false
          }
        }
      ],
        xAxis : [
          {
            type : 'category',
            data:[],   
            splitLine: {
              show: true
            },
            axisTick:{
              show: false
            },
            axisLine: {
              show: false
            }
          }
      ],
      series : []
    };
    //拼装series
    var series = dataMap.series;
    for(var i in series){
      if(series[i]!=undefined){
            var serie = {
                name:series[i].name,
                type:'line',
                markLine:{
                  data:[
                  ]
                },
                data:series[i].data,
                /*areaStyle: {normal: {color:'rgba(26,123,250,0.25)'}},*/
                itemStyle: {
                  normal: {
                    color:series[i].color     
                    }
                }

        }
        option.series.push(serie);
            
          }
    }
    //拼装x轴
    option.xAxis[0].data = dataMap.xAxis;
    //拼装legend
/*    option.legend.data = dataMap.legend;*/
    myChart.setOption(option);

  }


}